﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;

namespace WebSys.UI.Control.ZhengShou
{
    public class Force_newControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        TextBox txtCaseid, txtID;
        MPCalendar txtQcrq;
        DropDownList ddlQcfs;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();
            string strid = base.Page.Request["ID"];
            string strcaseid = base.Page.Server.UrlDecode(base.Page.Request["caseid"]); 
            if (string.IsNullOrEmpty(strcaseid))
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("案件号未填写！", "window.close();");
            }
            if (!base.Page.IsPostBack)
            {
                QSDATADLL();
                if (!string.IsNullOrEmpty(strcaseid)) { txtCaseid.Text = strcaseid; }
                if (string.IsNullOrEmpty(strid)) { txtID.Text = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(); } 
                else { 
                    txtID.Text = strid;
                    EluZSProvider.QZZXXX qzzxxx = _EluZSDataProvider.GetQZZXXX(strid);
                    txtCaseid.Text = qzzxxx.CASEID;
                    if (qzzxxx.QCRQ.HasValue) { txtQcrq.Text = qzzxxx.QCRQ.Value.ToShortDateString(); }
                    ddlQcfs.SelectedValue = qzzxxx.QCFS;
                }
            }

            Button btn_Insert = (Button)FindControl("btn_Insert");
            btn_Insert.Click += new EventHandler(btn_Insert_Click);
        }
        protected void InitControl() {
            txtCaseid = (TextBox)FindControl("txtCaseid");
            txtID = (TextBox)FindControl("txtID");
            txtQcrq = (MPCalendar)FindControl("txtQcrq");
            ddlQcfs = (DropDownList)FindControl("ddlQcfs");
        }
        protected void btn_Insert_Click(object sender, EventArgs e)
        {
            EluZSProvider.QZZXXX qzzxxx = new EluZSProvider.QZZXXX();
            string strid = base.Page.Request["ID"];
            qzzxxx.ID = txtID.Text;
            qzzxxx.CASEID = txtCaseid.Text;
            qzzxxx.QCRQ = (string.IsNullOrEmpty(txtQcrq.Text) ? null : (DateTime?)Convert.ToDateTime(txtQcrq.Text));
            qzzxxx.QCFS = ddlQcfs.SelectedValue;

            base.Page.Session["nCount"] = "7";

            bool save = _EluZSDataProvider.SaveQZZXXX(strid, qzzxxx);

            Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptbasic1", "<script>windowClose('" + base.Page.Request["type"] + "');</script>");
        }
        protected void QSDATADLL() {
            List<EluZSProvider.Params> _params = _EluZSDataProvider.GetParams("强制执行方式");
            EluZSProvider.Params item = new EluZSProvider.Params();
            item.Keyname = "";
            item.Keyvalue = "0";
            _params.Insert(0, item);
            ddlQcfs.DataSource = _params;
            ddlQcfs.DataValueField = "keyvalue";
            ddlQcfs.DataTextField = "keyname";
            ddlQcfs.DataBind();
        }
    }
}


